﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MedicLibrary.Model;
using MedicLibrary.Controler;

namespace MedicLibrary.View
{
    public partial class frmHamLuong : Form
    {
      
        public delegate void saveHamLuong(float HamLuong, String DonVi);

        public saveHamLuong saveHL;

        public frmHamLuong()
        {
            InitializeComponent();
            
        }

        private void frmHamLuong_Load(object sender, EventArgs e)
        {
            cbxDonVi.DataSource = Session.getDanhSachDonVi();
            cbxDonVi.DisplayMember = "DonVi";
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtHamLuong.Text == "")
            {
                saveHL(0, cbxDonVi.Text);
                this.Close();
            }
            else if (txtHamLuong.Text != "")
            {
                saveHL(float.Parse(txtHamLuong.Text), cbxDonVi.Text);
                this.Close();
            }
            else
                this.Close();

        }

        private void txtHamLuong_KeyPress(object sender, KeyPressEventArgs e)
        {
            int isNumber = 0;
            e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber);
            if (isNumber == 0)
                if (e.KeyChar.ToString()!=".")
                    MessageBox.Show("Vui lòng chỉ nhập số vào ô Hàm lượng");
        }

   
    }
}
